﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using dbcntn;

namespace Campus.Main.Basic.InsertValues
{
    public partial class Bed : Default
    {
        public Bed()
        {
            InitializeComponent();
        }

        private string[] data = new string[2];
        public Bed(List<string> item):base(item)
        {
            InitializeComponent();
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            textBox1.Text = item[1];
            textBox1.Visible = false;
            aToDb.AddItem(comboBox1,"yurtdef");
            comboBox1.SelectedValue = item[1];
            aToDb.AddItem(comboBox2,"room","yurt_id",Int32.Parse(item[1]));
            comboBox2.SelectedValue = item[2];
            comboBox3.SelectedItem = item[3];
            button2.Click += button2_Click;
        }

        protected override void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length>0)
            {
                data[0] = Convert.ToString(comboBox2.SelectedValue);
                data[1] = Convert.ToString(comboBox3.SelectedValue); 
               //aToDb.UpdateTable("bed","description",val1,id);
                aToDb.UpdateTable("bed","room_id","bed_id",data[0],data[1],id);
                Close();
            }
            else
            {
                MessageBox.Show("Талланы толтургула!!!");
            }
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            Type t = typeof(Int32);
            if (comboBox1.SelectedValue.GetType() == t)
            {
                int a = Convert.ToInt32(comboBox1.SelectedValue);
                aToDb.AddItem(comboBox2, "room", "yurt_id", a);
                if (comboBox2.SelectedValue==null)
                {
                    comboBox3.DataSource = null;
                }
            }
        }

        private void comboBox2_SelectedValueChanged(object sender, EventArgs e)
        {
            Type t = typeof(Int32);
            if (comboBox2.SelectedValue.GetType() == t)
            {
                
            }
        }
    }
}
